<?php
    require_once "config.php";
    $sort = empty($_GET['sort']) ? '' : $_GET['sort'];
    if(empty($sort)){
        $shop_sql = $mysql->query("select * from dyspw_member where is_vip = 3 order by regtime DESC");
        $shop = $shop_sql->fetch_all(MYSQLI_ASSOC);
        $city_sql = $mysql->query("select * from dyspw_weblinktype where id =".$shop[0]['sort']);
        $city = $city_sql->fetch_all(MYSQLI_ASSOC);
    }else{
        if(isset($_GET['key']) && mb_strlen(trim($_GET['key']))){
            $shop_sql = $mysql->query("select * from dyspw_member where is_vip = 3 and sort = $sort and  username like '%".trim($_GET['key'])."%' order by regtime DESC");
        }else{
            $shop_sql = $mysql->query("select * from dyspw_member where is_vip = 3 and sort = $sort order by regtime DESC");
        }
        $shop = $shop_sql->fetch_all(MYSQLI_ASSOC);
        $city_sql = $mysql->query("select * from dyspw_weblinktype where id =".$sort);
        $city = $city_sql->fetch_all(MYSQLI_ASSOC);
    }

    // print_r($shop);exit;
 ?>
 <!DOCTYPE html>
 <html>

 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
   <title>商铺列表</title>
   <script src="js/mui.min.js"></script>
   <link href="css/mui.min.css" rel="stylesheet" />
   <link href="css/cate.css" rel="stylesheet" />
   <script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
   <script type="text/javascript" src="//webapi.amap.com/maps?v=1.4.1&key=fedad41056b27c3e8cc5eaca216434e9"></script>
   <script src="js/dsbridge.js" type="text/javascript"></script>
   <script type="text/javascript" charset="utf-8">
     mui.init();
   </script>
 <script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cb5d49b07e0a753dc8ee27ba2c73495d";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>

 <body>
   <div class="container">
     <div class="top">
       <div class="search">
         <div class="backBtn">
           <a href="javascript:history.back(-1);"><span class="mui-icon mui-icon-arrowleft"></span></a>
         </div>
         <div class="mui-input-row mui-search">
           <input type="search" class="mui-input-clear shopSearch" placeholder="<?php
           if(isset($_GET['key']) && mb_strlen(trim($_GET['key']))){
               echo trim($_GET['key']);
           }else{
               echo '搜索你想要的内容';
           }
           ?>">
         </div>
       </div>
       <div class="mui-slider banner">
         <div class="mui-slider-group">
           <div class="mui-slider-item"><a href="#"><img src="images/shop_list.png" /></a></div>
         </div>
       </div>
     </div>
     <div class="list">
         <?php if(!empty($shop)){foreach ($shop as $key => $val) {?>
             <a href="shop_goods_list.php?id=<?php echo $val['id']; ?>&lng=<?php echo $val['shop_lng']; ?>&lat=<?php echo $val['shop_lat']; ?>&name=<?php echo $val['username']; ?>">
             <div class="item mui-row">
               <div class="logo mui-col-xs-4">
                 <img src="<?php echo $val['avatar'] ?>" alt="">
               </div>
               <div class="content  mui-col-xs-8">
                 <div class="shopName">
                   <span class="name mui-ellipsis"><?php echo $val['username'] ?></span>
                   <span class="mark">促</span>
                 </div>
                 <div class="stars">
                   <img src="images/star.jpg" alt="">
                   <img src="images/star.jpg" alt="">
                   <img src="images/star.jpg" alt="">
                   <img src="images/star.jpg" alt="">
                   <img src="images/star.jpg" alt="">
                   <span>5.00</span>
                 </div>
                 <div class="address" style="line-height: 20px;">
                   <span class="cate"><?php echo $city[0]['classname'] ?></span>
                   <div class="add mui-ellipsis">
                     <img src="images/location.jpg" alt="">
                     <div class="location "><?php echo $val['shop_add'] ?></div>
                   </div>
                   <?php if(!empty($val['shop_lat']) && !empty($val['shop_lng'])){?>
                       <div class="julitxt" lng="<?php echo $val['shop_lng']; ?>" lat="<?php echo $val['shop_lat']; ?>" style="color: red;font-size: 16px;">0.0</div>
                   <?php } ?>
                 </div>
                 <div class="price" style="margin-top: 5px;">
                   <span class="mark">介绍：</span>
                   <div class="info" style="    height: 20px;line-height: 20px;overflow: hidden;"><?php if(!empty($val['intro'])){echo $val['intro'];}else{ echo '暂无介绍';} ?></div>
                 </div>
               </div>
             </div>
             </a>
         <?php }}else{?>
            <span style="display: inline-block;width: 80%;margin: 50px auto auto 10%;text-align: center;line-height: 50px;font-size: 14px;background: rgb(238, 238, 238);border-radius: 10px;letter-spacing: 2px;color: #929292;">未查询到商户</span>
         <?php } ?>

     </div>

   </div>
   <script type="text/javascript">
       //商城首页搜索
       $(".shopSearch").focus(function(){
           $(document).keyup(function(event){
               if(event.keyCode ==13){
                   var key = $('.shopSearch').val();
                   window.location.href='/xiaochengxu/shop_list.php?sort=<?php echo $_GET['sort']?>&key='+key
               }
           });
       });

       function getaddre() {
           var map, geolocation;
           map = new AMap.Map('allmap');
           map.plugin('AMap.Geolocation', function () {
               geolocation = new AMap.Geolocation({
                   enableHighAccuracy: true //是否使用高精度定位，默认:true
               });
               geolocation.getCurrentPosition();
               AMap.event.addListener(geolocation, 'complete', function (point) {
                   var p1 = [point.position.lng, point.position.lat];
                   $.each($(".julitxt"), function (k, v) {
                       if ($(this).attr("lng") != '' && $(this).attr("lat") != '') {
                           var lng = $(this).attr("lng");
                           var lat = $(this).attr("lat");
                           var p2 = [lng, lat];
                           var dis = AMap.GeometryUtil.distance(p1, p2);
                           var danwei;
                           if (dis > 1000) {
                               dis = dis / 1000;
                               dis = Math.round(dis);
                               danwei = 'km';
                           } else {
                               dis = Math.round(dis);
                               danwei = 'm';
                           }
                           $(this).html(dis + danwei);
                       }
                   });
               });
           });
       }
       getaddre();
   </script>
 </body>

 </html>
